'''
作者: 沙昊
邮箱: shahao@zju.edu.cn
功能: 
包含算法: 
Copyright (c) 2023 by 沙昊, All Rights Reserved. 
'''
import heapq

def topKFrequent(nums, k):
    map_ = {}
    for i in range(len(nums)):
        map_[nums[i]] = map_.get(nums[i],0)+1

        pri_que = []
        for key,freq in map_.items():
            heapq.heappush(pri_que,(freq,key))
            if len(pri_que)>k:
                heapq.heappop(pri_que)

        result_sha = [0] * k
        for i in range(k-1,-1,-1):
            result_sha[i] = heapq.heappop(pri_que)[1]

        return result_sha 
    
temp = input().split(" ")
nums = list(temp[0])
k = int( temp[1])

topKFrequent(nums,k)
